﻿using Eatime.Entitys;
using Eatime.Main.DataModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “分组项页”项模板在 http://go.microsoft.com/fwlink/?LinkId=234231 上提供

namespace Eatime.Main
{
    /// <summary>
    /// 显示分组的项集合的页。
    /// </summary>
    public sealed partial class Allmenu : Eatime.Main.Common.LayoutAwarePage
    {
        ShopDetailDataSource ShopDetailDataSource;
        public Allmenu()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// 使用在导航过程中传递的内容填充页。在从以前的会话
        /// 重新创建页时，也会提供任何已保存状态。
        /// </summary>
        /// <param name="navigationParameter">最初请求此页时传递给
        /// <see cref="Frame.Navigate(Type, Object)"/> 的参数值。
        /// </param>
        /// <param name="pageState">此页在以前会话期间保留的状态
        /// 字典。首次访问页面时为 null。</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // TODO: 将可绑定组集合分配到 this.DefaultViewModel["Groups"]
            // 允许已保存页状态重写要显示的初始项
            ShopDetailDataSource = (ShopDetailDataSource)navigationParameter;
            if (ShopDetailDataSource.Menus.Any())
            {
                
            itemGridView.ItemsSource = ShopDetailDataSource.Menus[0].Items;
            }

            Menu_Combox.ItemsSource = ShopDetailDataSource.Menus;
            Menu_Combox.SelectedIndex = 0;
            pageTitle.Text = ShopDetailDataSource.Shop.Title + "";
        }
        /// <summary>
        /// 保留与此页关联的状态，以防挂起应用程序或
        /// 从导航缓存中放弃此页。值必须符合
        /// <see cref="SuspensionManager.SessionState"/> 的序列化要求。
        /// </summary>
        /// <param name="pageState">要使用可序列化状态填充的空字典。</param>
        protected override void SaveState(Dictionary<String, Object> pageState)
        {

            pageState["SelectedItem"] = ShopDetailDataSource.Shop.Id.ToString();
        }


        private void ItemView_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void Menu_Combox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            ComboBox combox = (ComboBox)sender;
            Menu menu = ShopDetailDataSource[int.Parse(combox.SelectedValue.ToString())];
            itemGridView.ItemsSource = menu.Items;

        }
    }
}
